package stateAAs.animator {
	import org.agony2d.gpu.AAFacade;
	import org.agony2d.gpu.core.AnimatorAA;
	import org.agony2d.gpu.StateAA;
	import org.agony2d.gpu.TingedAnimatorAA;
	import org.agony2d.gpu.UntingedAnimatorAA;
	import org.agony2d.input.KeyboardManager;
	import org.agony2d.notify.AEvent;
	
public class Animator_StateAA extends StateAA {
  
    public function Animator_StateAA() {
        
    }
	/** overwritable... */
	override public function get smoothing() : Boolean {
		return true
	}
	
	/** overwritable... */
	override public function get tinted() : Boolean {
		return true
	}
	
	/** overwrite... */
	override public function get fullTex() : String {
		return "atlas"
	}
	
	private var m_animator:TingedAnimatorAA
	private var m_animator_A:UntingedAnimatorAA
	
	override public function enter():void {
		m_animator = new TingedAnimatorAA(AAFacade.getSheet("flight"))
		this.group.addNode(m_animator)
		m_animator.x = m_animator.y = 150
		m_animator.pivotX = m_animator.pivotY = 110
		m_animator.setActionByClipIndex(0, 1, 1)
		m_animator.setActionByClipIndex(1, 0, 1)
		
		//m_animator.play([0])
		m_animator.speedRatio = 1.5
		m_animator.alpha = 0.7
		m_animator.color = 0x4444dd
		
		m_animator_A = new UntingedAnimatorAA(AAFacade.getSheet("flight"))
		this.group.addNode(m_animator_A)
		m_animator_A.x = 400
		m_animator_A.y = 150
		m_animator_A.pivotX = m_animator_A.pivotY = 110
		m_animator_A.setActionByClipIndex(0, 0, 1).callback = function():void {
			trace("Action_0")
		}
		m_animator_A.setActionByClipIndex(1, 1, 1).callback = function():void {
			trace("Action_1")
		}
		m_animator_A.setActionByClipIndex(2, 2, 1).callback = function():void {
			trace("Action_2")
		}
		m_animator_A.setActionByClipIndex(3, 3, 2).callback = function():void {
			trace("Action_3")
		}
		m_animator_A.setActionByClipIndex(4, 4, 1).callback = function():void {
			m_animator_A.frame = 1
		}
		
		KeyboardManager.getInstance().getState().press.addEventListener("ONE", function(e:AEvent):void {
			m_animator_A.play([1])
		})
		KeyboardManager.getInstance().getState().press.addEventListener("TWO", function(e:AEvent):void {
			m_animator_A.play([2])
		})
		KeyboardManager.getInstance().getState().press.addEventListener("THREE", function(e:AEvent):void {
			m_animator_A.play([0, 1])
		})
		KeyboardManager.getInstance().getState().press.addEventListener("FOUR", function(e:AEvent):void {
			m_animator_A.play([2, 0])
		})
		KeyboardManager.getInstance().getState().press.addEventListener("FIVE", function(e:AEvent):void {
			m_animator_A.play([3, 1])
		})
		KeyboardManager.getInstance().getState().press.addEventListener("SIX", function(e:AEvent):void {
			m_animator_A.play([4, 1])
		})
		KeyboardManager.getInstance().getState().press.addEventListener("PLUS", function(e:AEvent):void {
			m_animator_A.frame++
		})
		KeyboardManager.getInstance().getState().press.addEventListener("MINUS", function(e:AEvent):void {
			m_animator_A.frame--
		})
		KeyboardManager.getInstance().getState().press.addEventListener("LEFT", function(e:AEvent):void {
			m_animator_A.speedRatio -= 0.1
		})
		KeyboardManager.getInstance().getState().press.addEventListener("RIGHT", function(e:AEvent):void {
			m_animator_A.speedRatio += 0.1
		})
		KeyboardManager.getInstance().getState().straight.addEventListener("W", function(e:AEvent):void {
			m_animator_A.scaleX = m_animator_A.scaleY += 0.02
		})
		KeyboardManager.getInstance().getState().straight.addEventListener("S", function(e:AEvent):void {
			m_animator_A.scaleX = m_animator_A.scaleY -= 0.02
		})
		KeyboardManager.getInstance().getState().straight.addEventListener("A", function(e:AEvent):void {
			m_animator_A.rotation -= 1
		})
		KeyboardManager.getInstance().getState().straight.addEventListener("D", function(e:AEvent):void {
			m_animator_A.rotation += 1
		})
		m_animator_A.addEventListener(AEvent.PRESS, onTouch)
		m_animator_A.addEventListener(AEvent.MOVE, onTouch)
		m_animator_A.addEventListener(AEvent.RELEASE, onTouch)
		m_animator_A.addEventListener(AEvent.LEAVE , onTouch)
		m_animator_A.addEventListener(AEvent.OVER , onTouch)
	}
	
	private function onTouch(e:AEvent):void {
		trace(e.target, e.type)
	}
}
}